{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from CSqQueue import CSqQueue\n",
    "qu = CSqQueue()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def pushk(qu,k,e):\n",
    "    n = qu.size()\n",
    "    if k < 1 or k > n+1:\n",
    "        return False\n",
    "    if k<=n:\n",
    "        for i in range(1,n+1):\n",
    "            if i == k:\n",
    "                qu.push(e)\n",
    "            x = qu.pop()\n",
    "            qu.push(x)\n",
    "    else:\n",
    "        qu.push(e)\n",
    "    return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def popk(qu,k):\n",
    "    n = qu.size()\n",
    "    assert k >= 1 and k <= n\n",
    "    for i in range(1,n+1):\n",
    "        x = qu.pop()\n",
    "        if i != k:\n",
    "            qu.push(x)\n",
    "        else:\n",
    "            e = x\n",
    "    return e"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.3 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "d12a6980af1de3549060b7b451d48d445ec6b4aaeaf0b0e12a509d2182e95745"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
